using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Xfinity.Entities;
using Xfinity.Entities.Managers;

namespace Xfinity.Engine.SceneGraph
{
    /// <summary>
    /// A renderable scene graph.
    /// </summary>
    [Serializable]
    public class SceneGraph : GlobalManager, IDrawable
    {
        SceneNode root;

        private static int maxModelsPerNode = 10;

        /// <summary>
        /// Gets or sets the max models per node.
        /// </summary>
        /// <value>The max models per node.</value>
        public static int MaxModelsPerNode
        {
            get { return maxModelsPerNode; }
            set { if (value > 0) { maxModelsPerNode = value; } }
        }

        /// <summary>
        /// Gets the root node.
        /// </summary>
        /// <value>The root.</value>
        public SceneNode Root
        {
            get { return root; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SceneGraph"/> class.
        /// </summary>
        /// <param name="models">The models.</param>
        /// <param name="game">The game.</param>
        public SceneGraph(IEnumerable<IPhysicalEntity> models, Game game)
            : base("Scene graph", true, game)
        {
            root = new SceneNode(models, null, Game);
        }
        public SceneGraph()
            : this(null, null)
        {

        }
        /// <summary>
        /// Initialises the scene graph.
        /// </summary>
        public override void Initialize() 
        {
            root.Initialize();
            base.Initialize();
        }

        /// <summary>
        /// Draws the contents of the octree.
        /// </summary>
        /// <param name="gameTime">Snapshot of the game's timing state.</param>
        public override void Draw(GameTime gameTime)
        {
            root.Draw(gameTime);
        }


        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            root.LoadGraphics(loadAllContent);
            base.LoadGraphicsContent(loadAllContent);
        }

        public void LoadGraphics(bool loadAllContent)
        {
            LoadGraphicsContent(loadAllContent);
        }
    }
}